﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Windows.Forms;

namespace DispatchAssist.AppHost
{
    public class SkinConfig
    {
        public static SkinConfig Instance = new SkinConfig();

        private string skinFile;
        public string SkinFile
        {
            get
            {
                return "Skins/" + skinFile;
            }
            set
            {
                skinFile = value;               
            }
        }

        private bool enabled;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
            }
        }

        private SkinConfig()
        {
            skinFile = ConfigurationManager.AppSettings["Skin"];
            enabled = (ConfigurationManager.AppSettings["EnableSkin"] == "1");
        }

        public Sunisoft.IrisSkin.SkinEngine EnsureSkin(Form form)
        {
            var skin = new Sunisoft.IrisSkin.SkinEngine(((System.ComponentModel.Component)(form)));
            skin.SerialNumber = "";
            skin.SkinFile = "Skins/" + skinFile;
            skin.Active = this.enabled;
            return skin;
        }

        public void UpdateSkin(Form form, Sunisoft.IrisSkin.SkinEngine ske)
        {
            if (enabled)
            {
                if (ske != null)
                {
                    ske.SkinFile = SkinFile;
                    ske.Active = true;
                }
            }
            else
            {
                if (ske != null)
                {
                    ske.Active = false;
                    ske.SkinFile = string.Empty;
                }
            }
        }
    }
}
